package com.gitee.swsk33.websocketdemo.config;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;
import jakarta.annotation.PostConstruct;
import org.springframework.context.annotation.Configuration;

/**
 * FastJSON全局配置
 */
@Configuration
public class FastJSONConfig {

	/**
	 * 序列化策略配置
	 */
	@PostConstruct
	private void writerConfig() {
		// 基于字段而不是getter和setter序列化
		JSON.config(JSONWriter.Feature.FieldBased);
		// 自动序列化长整型为字符串
		JSON.config(JSONWriter.Feature.WriteLongAsString);
	}

	/**
	 * 反序列化策略配置
	 */
	@PostConstruct
	private void readerConfig() {
		// 基于字段而不是getter和setter反序列化
		JSON.config(JSONReader.Feature.FieldBased);
	}

}